﻿using UnityEngine;
using System.Collections;

public class ClickStraight : MonoBehaviour
{
	public GameObject objDrawLine;
	private bool CheckClick = true;
	// Use this for initialization
	void Start ()
	{
	
	}
	
	// Update is called once per frame
	void Update ()
	{
	
	}

	public void InitClickStraight(GameObject obj)
	{
		objDrawLine = obj;
	}

	public void SetCheckClick(bool check)
	{
		CheckClick = check;
	}

	void OnMouseDown() {
		Debug.Log ("ClickStraight");
		if (CheckClick) 
		{
			GameManager gameManager = GameObject.Find ("ListPoint").GetComponent<GameManager>();

			for (int i = 0; i < gameManager.listObjDrawLine.Count; i++) {
				if (gameManager.listObjDrawLine [i].name == objDrawLine.name) {
					gameManager.listObjDrawLine.Remove (gameManager.listObjDrawLine[i]);
				}
			}
			string[] name = objDrawLine.name.Split ('-');
			for (int i = 0; i < gameManager.listStraight.Count; i++) {
				if (gameManager.listStraight[i].point_1.name == name[0] && gameManager.listStraight[i].point_2.name == name[1]) {
					gameManager.listStraight.Remove (gameManager.listStraight[i]);
					break;
				}
			}
				
			Destroy (objDrawLine);
		}

	}
}

